<style>
.chatfoot {
    position: fixed;
	padding:0.5rem;
	width:100%;
	bottom:0;
	z-index: 108;
}
.chatfoot .chatbtnup{
	background:#fff;
	background:var(--bg-base-2,#fff);
	border-radius:0.5rem;
	box-shadow:0 6px 10px 0 rgba(42,60,79,.1);
	box-sizing:border-box;
	border: 1px solid rgba(0,0,0,.08);
	max-width:var(--chat-area-max-width);
	position:relative;
	width:100%
}
.label-gray{
	background-color:#f2f2f2;
	color:#333;
	border-radius:1rem;
	padding:0.3rem;
	font-size:0.7rem
}
.label-gray.active{
	background-color:#e8fcf8;
	color:#18bc9c;
}
</style>
<div class="chatfoot" style="height:auto">
    <div class="chatbtnup" style="padding:0;width:100%;">
		<div class="fui-cellone" style="padding:0.5rem;background:#f9fafb;border-top-left-radius:0.5rem;border-top-right-radius:0.5rem">
			<div class="fui-cellone-text">
				<i class="icon icon-bianji"></i> {{pagedata.nowtype.title||'无'}}
			</div>
			<div class="fui-cellone-remark noremark" style="margin-left:0.5rem;width:auto;">
				<span ng-if="pagedata.nowtype.id>0" class="label label-gray" ng-click="pagedata.nowtype=''"><i class="icon icon-close"></i> 关闭</span>
				<span ng-if="!pagedata.nowtype.id" class="label label-gray" ng-click="access_json('/index/')"><i class="icon icon-qiehuan"></i> 新对话</span>
			</div>
		</div>
		<div class="fui-cellone">
			<div class="fui-cellone-text">
				<textarea class="weui_textarea" style="width:100%;" ng-model="pagedata.post.wenmsg" placeholder="请输入内容..." rows="2"></textarea>
			</div>
		</div>
		<div class="fui-cellone" style="padding-top:0">
			<div class="fui-cellone-text">
				<span ng-class="{'label label-gray':1,'active':pagedata.post.issikao==1}" ng-click="toogle(pagedata.post,'issikao',[0,1])"><i class="icon icon-code"></i> 深度思考</span>
				<span ng-class="{'label label-gray':1,'active':pagedata.post.iswww==1}" ng-click="toogle(pagedata.post,'iswww',[0,1])"><i class="icon icon-customs-clearance" style="font-size:0.65rem"></i> 搜索资料</span>
			</div>
			<div class="fui-cellone-remark noremark" style="margin-left:0.5rem;width:auto">
				<div class="c" style="line-height:1.5rem;width:1.5rem;height:1.5rem;border-radius:1.5rem;background:{{pagedata.post.wenmsg?'#07c160;':'#f2f2f2;'}}">
					<i id="searchsub" class="icon icon-zhifeiji" ng-click="pagedata.submitform()" style="font-size:1rem;color:#fff"></i>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
const textContainer = document.getElementById('svposttext');
scope.pagedata.scrollTop=function(){
	$('#svposttext').animate({scrollTop:textContainer.scrollHeight+100},300);
	 if(scope.pagedata.isanswer){
		setTimeout(function(){
		   scope.pagedata.scrollTop();
		},2000);
	 }
}
let index = 0;
scope.pagedata.damsg121=function(key){
   scope.pagedata.isanswer=true;
   var targetText=scope.pagedata.newanswer;
   const typingInterval = setInterval(() => {
      if (index < targetText.length) {
          scope.pagedata.listnew[key].answer += targetText[index];
		  index++;
          scope.$evalAsync();
		  // 自动滚动到容器底部
         
      } else {
          clearInterval(typingInterval);
		  index=0;
		  scope.pagedata.isanswer=false
      }
    }, 50);
	setTimeout(function(){
	  scope.pagedata.scrollTop()
	},8000);
}

scope.pagedata.submitform=function(){
	//苹果手机键盘归让页面归位
	window.scroll(0,0); //让页面归位
	scope.pagedata.listnew=scope.pagedata.listnew?scope.pagedata.listnew:[];
	var text = scope.pagedata.post.wenmsg;
	if(scope.pagedata.isget){
		scope.message('还有一个问题正在思考中，请稍后提问！','error');
		return false;
	}
	if(scope.pagedata.isanswer){
		scope.message('还有一个问题正在回答中，请稍后提问！','error');
		return false;
	}
	scope.post_json('jy_agentmcp/chat/addlog/',{'msg':text},function(data){
		scope.pagedata.listnew = scope.pagedata.listnew.concat(data.log)
		scope.pagedata.post.wenmsg='';
		var key=scope.pagedata.listnew.length;
			key--
		if(data.log && data.log.id){
			scope.pagedata.isget=true;
			scope.$evalAsync();
			scope.get('jy_agentmcp/chat/getmsg/msg='+text+'&logid='+data.log.id+'&key='+key,function(res){
				console.log(res);
				scope.pagedata.isget=false;
				if(res.fail==1){
					scope.pagedata.showtype=true;
					scope.$evalAsync();
					return false;
				}
				if(res.msg){
					scope.pagedata.listnew[key].answer='';
					scope.pagedata.newanswer=res.msg;
					scope.pagedata.damsg121(res.key);
					$('#svposttext').animate({scrollTop:100000},300);
					scope.$evalAsync();
				}
			});	
		}else{
			scope.message(data.msg,'error');
		}
	});	
}
if(scope.pagedata.post.isupwenmsg==1){
	scope.pagedata.post.wenmsg=decodeURIComponent(scope.pagedata.post.wenmsg);
	scope.pagedata.submitform();
}
//手机软键盘--搜索
$("body").keydown(function() {
    if (event.keyCode == "13") {
        $('#searchsub').click();
    }
});
</script>